<?php
/**
 * LOG
 * 
 * Provee de funciones para almacenar en el Log del sitio
 * 
 * @author Jose Flores <josefloressv@gmail.com>
 * 
*/
final class Log{

  private static $instance;    
	private static $log_file="/var/log/clavoycanela.log";

  private function __construct(){}
  private function __clone(){}    
    
  /**
  * UNA SOLA INSTANCIA 
  */
  public static function getInstance()
  {
    if (  !self::$instancia instanceof self)
    {
       self::$instancia = new self;
    }
    return self::$instancia;
  }
    
    static final function write($titulo, $msg="") {
        try {
            $backTrace = @debug_backtrace();
            $info_arc = Array();
            $info_arc['method'] = isset($backTrace[1]['function']) ? $backTrace[1]['function'] : '--';
            $info_arc['errfile'] = $backTrace[0]['file'];
            $info_arc['errline'] = $backTrace[0]['line'];
            $temp = "\n========================================================================\n" .
                    "-->  " . $titulo . "\n" .
                    "Fecha: " . date("Y/m/d h:i:s a") . "\n" .
                    "IP: " . $_SERVER['REMOTE_ADDR'] . "\n" .
                    "Metodo: " . $info_arc['method'] . "\n" .
                    "Linea: " . $info_arc['errline'] . "\n" .
                    "Archivo: " . $info_arc['errfile'] . "\n" .
                    "Detalle:\n" . $msg .
                    "\n------------------------------------------------------------------------\n";
            error_log($temp, 3, self::$log_file);
        } catch (Exception $exc) {
            ;
        }
    }    
}    
?>